
//存储token
export function setToken(token, expirationSeconds) {
    const expirationTime = new Date().getTime() + expirationSeconds * 1000;
    localStorage.setItem('token', token);
    localStorage.setItem('tokenExpiration', expirationTime);
}

//获取token
export function getToken() {
    const token = localStorage.getItem('token');
    const expirationTime = localStorage.getItem('tokenExpiration');

    if (token && expirationTime) {
        const currentTime = new Date().getTime();
        if (currentTime < expirationTime) {
            return token;
        } else {
            // token 已过期，清除 token
            localStorage.removeItem('token');
            localStorage.removeItem('tokenExpiration');
            return null;
        }
    } else {
        return null;
    }
}